//
//  UserColleagueTableViewCell.m
//  XinKaiFa55like
//
//  Created by junseek on 2017/3/26.
//  Copyright © 2017年 55like lj. All rights reserved.
//

#import "UserColleagueTableViewCell.h"
#import "UILabel+atrribulttext.h"

@interface UserColleagueTableViewCell (){    //
    
    NSIndexPath *tempIndexPath;
    NSDictionary *tempDic;
    
    
    
    UIImageView *imageLogo;
    UILabel *lblTitle;
    
    UIButton *btnTel;
    UIView *viewLine;
    
    
}

@end
@implementation UserColleagueTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        
        imageLogo=[RHMethods imageviewWithFrame:CGRectMake(10, 10, 44, 44) defaultimage:@"newPic"];
        [self addSubview:imageLogo];
        [[Utility Share] viewLayerRound:imageLogo borderWidth:0.1 borderColor:[UIColor clearColor]];
        
        lblTitle=[RHMethods labelWithFrame:CGRectMake(80, 0, kScreenWidth-140, 44) font:fontTitle color:rgbTitleColor text:@""];
        [self addSubview:lblTitle];
        
        btnTel=[RHMethods buttonWithFrame:CGRectMake(kScreenWidth-50, 0, 50, 44) title:nil image:@"" bgimage:nil];
        [self addSubview:btnTel];
        [btnTel setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 15)];
        [btnTel setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
        [btnTel addTarget:self action:@selector(telButtonClicked) forControlEvents:UIControlEventTouchUpInside];
        
        
        viewLine=[RHMethods lineViewWithFrame:CGRectMake(0, 43.5, kScreenWidth, 0.5)];
        [self addSubview:viewLine];
        
    }
    return self;
}

//内容更新
-(void)setValueForDictionary:(NSDictionary *)dic indexPath:(NSIndexPath *)indexPath type:(NSString *)strType{
    tempIndexPath=indexPath;
    tempDic=dic;
    lblTitle.attributedText=nil;
    lblTitle.text=[dic valueForJSONStrKey:@"name"];
    lblTitle.textColor=rgbTitleColor;
    lblTitle.font=fontTitle;
    float f_t_w=10;
    NSArray *arrayT=[dic objectForJSONKey:@"list"];
    float fx=[strType isEqualToString:@"search"]?10:f_t_w*([[dic valueForJSONStrKey:@"num"] integerValue]);
    if (fx == 0) {
        fx = 10;
    }
    viewLine.frame=CGRectMake(fx, 43.5, kScreenWidth-fx, 0.5);
    btnTel.hidden=NO;
    [btnTel setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 15)];
    if (arrayT) {
        //部门变色
        if ([[dic valueForJSONStrKey:@"num"] isEqualToString:@"3"]) {
            lblTitle.textColor=rgbTxtDeepGray;
        }
        //还有下一级
        [btnTel setImage:[UIImage imageNamed:@"txlxjt"] forState:UIControlStateSelected];
        [btnTel setImage:[UIImage imageNamed:@"v3JianTou"] forState:UIControlStateNormal];
        btnTel.selected= [[dic valueForJSONStrKey:@"select"] isEqualToString:@"1"];
        imageLogo.hidden=YES;
        lblTitle.frame=CGRectMake(fx, 0, X(btnTel)-fx, 44);
         btnTel.userInteractionEnabled=NO;
        btnTel.frameHeight=44;
    }else{
        btnTel.frameHeight=60;
        [btnTel setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 30)];
        btnTel.selected = NO;
        [btnTel setImage:[UIImage imageNamed:@"phbfhone"] forState:UIControlStateNormal];
        btnTel.userInteractionEnabled=YES;
        if (![[dic valueForJSONStrKey:@"tel"] notEmptyOrNull]) {
            btnTel.hidden=YES;
        }
        [imageLogo imageSizeWithURL:[dic valueForJSONStrKey:@"logo"] useProgress:NO useActivity:NO];
        imageLogo.hidden=NO;
        imageLogo.frameX=fx;
        lblTitle.frame=CGRectMake(XW(imageLogo)+f_t_w, 0, X(btnTel)-XW(imageLogo)-f_t_w, 60);
        lblTitle.font=Font(16);
        lblTitle.text=[NSString stringWithFormat:@"%@\n%@",[dic valueForJSONStrKey:@"name"],[dic valueForJSONStrKey:@"position"]];
        if ([[dic valueForJSONStrKey:@"position"] notEmptyOrNull]) {
            [lblTitle setColor:rgbTxtDeepGray font:Font(14) contenttext:[dic valueForJSONStrKey:@"position"]];
        }
        if ([lblTitle.text notEmptyOrNull]) {
            [lblTitle setAllTextLineSpacing:5];
        }
        
        viewLine.frameY=59.5;
    }
//    if ([[dic valueForJSONStrKey:@"num"] integerValue]==4) {
//       
//    }
    
    //80
}

#pragma mark button
-(void)telButtonClicked{
    UIWebView*callWebview =[[UIWebView alloc] init];
    NSString *telUrl = [NSString stringWithFormat:@"tel:%@",[tempDic valueForJSONStrKey:@"tel"]];//[tempDic valueForJSONStrKey:@"mobile"]
    NSURL *telURL =[NSURL URLWithString:telUrl];// 貌似tel:// 或者 tel: 都行
    [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
    //记得添加到view上
    [self addSubview:callWebview];

}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
